<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>我的日程计划管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	
<style type="text/css">
/*  body{
	background-color:#e1e1e1 !important;
} */ 
.navbar{
	background-color:#8192D6 !important;
	height:55px;
	line-height:55px !important;
}
.main-content{
	margin-left:90px !important;
	margin-bottom: 8px;
	padding-top: 8px !important;
	line-height:36px;
}
.page-content{
	margin:0 100px !important;
	border:1px solid #e1e1e1;
	border-radius:15px;
}	
.nav-search{
	right:112px !important;
} 
.bootbox-radio{
	width:30px;
	margin-right:30px;
}
.number{
	font-weight:bloder;
}
.page-header h1{
	font-style: italic;
}
.admin{
	text-shadow: 5px 2px 3px #a49f9f;
}
/* .fc-header{
	padding-top:5px !important;
} */
</style>
		<!-- basic styles -->
		<link href="css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/font-awesome.min.css" />
		<link rel="stylesheet" href="css/ace-skins.min.css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="css/fullcalendar.css" />
		<!-- fonts -->
		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
		<!-- ace styles -->
		<link rel="stylesheet" href="css/ace.min.css" />
		<link rel="stylesheet" href="css/ace-rtl.min.css" />
		<link rel="stylesheet" href="css/ace-skins.min.css" />
		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="css/ace-ie.min.css" />
		<![endif]-->
		<!-- inline styles related to this page -->
		<!-- ace settings handler -->
		<script src="js/ace-extra.min.js"></script>

		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!--[if lt IE 9]>
		<script src="assets/js/html5shiv.js"></script>
		<script src="assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body class="skin-2">
		<div class="navbar navbar-default" id="navbar">
			<script type="text/javascript">
				try{ace.settings.check('navbar' , 'fixed')}catch(e){}
			</script>

			<div class="navbar-container" id="navbar-container">
				<div class="navbar-header pull-left">
					<a href="#" class="navbar-brand">
						<small class="admin">
							<i class="icon-leaf"></i>
							Super Admin
						</small>
					</a><!-- /.brand -->
				</div><!-- /.navbar-header -->
			</div><!-- /.container -->
		</div>

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<div class="breadcrumbs" id="breadcrumbs">
				<div class="main-content">
					
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Calendar</li>
						</ul><!-- .breadcrumb -->

						<div class="nav-search" id="nav-search">
							<form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
							</form>
						</div><!-- #nav-search -->
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>
								Full Calendar日志管理系统
								<small>
									<i class="icon-double-angle-right"></i>
									具有可拖动和可编辑的事件
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="row">
									<div class="col-sm-9">
										<div class="space"></div>

										<div id="calendar"><!-- 这里是日历内容 --></div>
									</div>

									<div class="col-sm-3">
										<div class="widget-box transparent">
											<div class="widget-header">
												<h4><a href="tables.jsp">查看所有事件列表</a></h4>
											</div>

											<div class="widget-body">
												<div class="widget-main no-padding">
													<div id="external-events">
													<!-- external-event初始化每个事件 -->
														<div class="external-event label-success" data-class="label-success">
															<i class="icon-move"></i>
															已完成事件(<span class="number" id="successNum"></span>)
														</div>

														<div class="external-event label-danger" data-class="label-danger">
															<i class="icon-move"></i>
															未完成事件(<span class="number" id="dangerNum"></span>)
														</div>


														<div class="external-event label-yellow" data-class="label-yellow">
															<i class="icon-move"></i>
															进行中事件 (<span class="number" id="yelloNum"></span>)
														</div>
														<div class="external-event label-info" data-class="label-info">
															<i class="icon-move"></i>
															计划中事件(<span class="number" id="infoNum"></span>)
														</div>

														<label>
															<input type="checkbox" class="ace ace-checkbox" id="drop-remove" />
															<span class="lbl"> 拖拽后删除事件</span>
														</label>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div><!-- /.main-content -->

				<div class="ace-settings-container" id="ace-settings-container">
					<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
						<i class="icon-cog bigger-150"></i>
					</div>

					<div class="ace-settings-box" id="ace-settings-box">
						<div>
							<div class="pull-left">
								<select id="skin-colorpicker" class="hide">
								    <option data-skin="default" value="#438EB9">#C6487E</option>
									<option data-skin="skin-1" value="#222A2D">#222A2D</option>
									<option data-skin="skin-2" value="#C6487E">#438EB9</option>
									<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
								</select>
							</div>
							<span>&nbsp;更改背景颜色</span>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar" />
							<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar" />
							<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs" />
							<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" />
							<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container" />
							<label class="lbl" for="ace-settings-add-container">
								Inside
								<b>.container</b>
							</label>
						</div>
					</div>
				</div><!-- /#ace-settings-container -->
			</div><!-- /.main-container-inner -->

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="icon-double-angle-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->
	<!-- 	<div id="test" style="width:100%; height:100px; border:1px solid red;">
		
		</div> -->

		<!-- basic scripts -->

		<!--[if !IE]> -->

		<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<![endif]-->

		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>

		<script src="js/bootstrap.min.js"></script>
		<script src="js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="js/jquery.ui.touch-punch.min.js"></script>
		<script src="js/fullcalendar.min.js"></script>
		<script src="js/bootbox.min.js"></script>

		<!-- ace scripts -->

		<script src="js/ace-elements.min.js"></script>
		<script src="js/ace.min.js"></script>

		<!-- inline scripts related to this page -->

<script type="text/javascript">
	
jQuery(function($) {
	$.ajax({
		url:"findEvent",
		type:"get",
		dataType:"json",
		cache:true,
		success:function(data){		
		 var msg = JSON.stringify(data)
		 //alert(data);
			
			var info = data[0].info;
			var yello = data[0].yello;
			var success = data[0].success;
			var danger = data[0].danger;
			$("#infoNum").html(info);
			$("#yelloNum").html(yello);
			$("#successNum").html(success);
			$("#dangerNum").html(danger);			
		},
		error:function(msg){
			//alert("error");
		}
	})
/* initialize the external events
	-----------------------------------------------------------------*/

	$('#external-events div.external-event').each(function() {

		// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
		// it doesn't need to have a start or end
		var eventObject = {
			title: $.trim($(this).text()) // use the element's text as the event title
		};

		// store the Event Object in the DOM element so we can get to it later
		$(this).data('eventObject', eventObject);

		// make the event draggable using jQuery UI
		$(this).draggable({
			zIndex: 999,
			revert: true,      // will cause the event to go back to its
			revertDuration: 0  //  original position after the drag
		});
		
	});
	/* initialize the calendar
	-----------------------------------------------------------------*/
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();

 	 $(document).ready(function(){
		$.ajax({
			url:"queryEvent",
			type:"get",
		  	dataType:"json", 
			cache:true,
			success:function(data){
		    // var objt = JSON.stringify(data); 
				var calendar = $('#calendar').fullCalendar({
					 buttonText: {
						prev: '<i class="icon-chevron-left"></i>',
						next: '<i class="icon-chevron-right"></i>'
					},			
					header: {
						left: 'prev,next today',
						center: 'title',
						right: 'month,Week,agendaDay'
					},
					events:data,
					editable: true,
					droppable: false, // 不允许右边统计可拖拽
					drop: function(date, allDay) { // this function is called when something is dropped
						// retrieve the dropped element's stored Event Object
						var originalEventObject = $(this).data('eventObject');
						var $extraEventClass = $(this).attr('data-class');			
						// we need to copy it, so that multiple events don't have a reference to the same object
						var copiedEventObject = $.extend({}, originalEventObject);
						
						// assign it the date that was reported
						copiedEventObject.start = date;
						copiedEventObject.allDay = allDay;
						if($extraEventClass) copiedEventObject['className'] = [$extraEventClass];				
						// render the event on the calendar
						// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
						$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);				
						// is the "remove after drop" checkbox checked?
						if ($('#drop-remove').is(':checked')) {
							// if so, remove the element from the "Draggable Events" list
							$(this).remove();
						}				
					}
					,
					selectable: true,
					selectHelper: true,
					select: function(start, end, allDay) {
						bootbox.prompt("添加新事件：", function(title) {						
							if (title !== null) {
								calendar.fullCalendar('renderEvent',
									{
										title: title,
										start: start,
										end: end,
										allDay: allDay
									},
									true // make the event "stick"
								);
								//这里绑定添加数据库事件
								$.ajax({
									url:"addEvent",
									type:"post",
									data:{"title":title,"start":start,"end":end,"className":"label-info"},
									success:function(){
										//alert("SUCCESS");
									},
									error:function(msg){
										//alert(msg);
									}
								})
							}
						});
						calendar.fullCalendar('unselect');		
					},
					
					eventClick: function(calEvent, jsEvent, view) {
						var form = $("<form class='form-inline'><label>改变事件名称 &nbsp;</label></form>");
						form.append("<input class='middle changeLength' autocomplete=off type=text value='" + calEvent.title + "' /> ");
						form.append("<button type='submit' class='btn btn-sm btn-success'><i class='icon-ok'></i> 保存</button>");
						var oldName = calEvent.title;
						var startTime = calEvent.start;
						var endTime = calEvent.end;
						var div = bootbox.dialog({
							message: form,					
							buttons: {
								"delete" : {
									"label" : "<i class='icon-trash'></i>删除",
									"className" : "btn-sm btn-danger",
									"callback": function() {
										$.ajax({
											url:"deleteEvent",
											type:"post",
											data:{"title":oldName,"start":startTime,"end":endTime},
											success:function(){			
											},
											error:function(mas){
												alert("数据库删除失败!");
											}
										});
										calendar.fullCalendar('removeEvents' , function(ev){
											return (ev._id == calEvent._id);
										})
									}
								} ,
								"close" : {
									"label" : "<i class='icon-remove'></i> 关闭",
									"className" : "btn-sm"
								} 
							}
						});
						
						form.on('submit', function(){
							calEvent.title = form.find("input[type=text]").val();
							calendar.fullCalendar('updateEvent', calEvent);
							div.modal("hide");
							$.ajax({
								url:"updateEvent",
								type:"post",
								data:{"oldName":oldName,"title":calEvent.title},
								success:function(){
								},
								error:function(msg){
									//alert("error");
								}
							})
							return false;
						});	
						//console.log(calEvent.id);
						//console.log(jsEvent);
						//console.log(view);
						// change the border color just for fun
						//$(this).css('border-color', 'red');
					}		
				}); //日历结束			
	},
	 error: function(XMLHttpRequest, textStatus, errorThrown) {
		  alert(XMLHttpRequest.status);
		/* alert(XMLHttpRequest.readyState);
		 alert(textStatus); */
	 }
})  //ajax结束
			
 	}); //document结束 
	
})
		</script>
	<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>

</body>
</html>